#include <pthread.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
//#include "CommFormat.h"
#include "socket_lib/SocketException.h"
//#include "timer/timer.h"
#include "select/MultiClient.h"

#include <sys/stat.h>   //mkfifo()
#include <fcntl.h>      //O_WRONLY O_RDONLY
#include <stdlib.h>	//exit()

#define FIFOPATH1 "/home/xbq/dev/test/multi_client/fifo1"
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

using namespace std;

int main (void)
{
	pthread_t tid1, tid2;
	char timer_over_msg[] = "the timer failed to create.";
	mkfifo(FIFOPATH1, FILE_MODE);
	ofstream db_log;
	
	char log_file_path[30], h_m_s[100];
	struct tm* nowtime;
	time_t nt;

	nt = time(NULL);
	nowtime = localtime(&nt);
	strftime(log_file_path, sizeof(log_file_path), "./log_files/%F.db.log", nowtime);
	db_log.open(log_file_path, ios::app);
	//cout << "Yes" << endl;

	strftime(h_m_s, sizeof(h_m_s), "%T.", nowtime);
	db_log << "Process was started at " << h_m_s << endl;
	pthread_create(&tid1, NULL, multi_select, NULL);
	pthread_join(tid1, 0);
	unlink(FIFOPATH1);
	return 0;
}

